#!/bin/bash

set -e
tar_name="icustom-web.tar"

node_type="icustom-web"

if [ -z "$node_type" ]; then
  echo ">>>>>>>> node type is empty >>  "
  exit 0
fi

workspace=$(pwd)

echo "ready to stop container $node_type"
docker stop $node_type || echo "stop container $node_type failed"

echo "ready to rm container $node_type"
docker rm $node_type || echo "rm container $node_type failed"
echo "rm container $node_type complete"

img=`docker load -i $workspace/$tar_name | awk -F " " '{print $3}'`
echo "load image $img success"
echo "$img===================================================="

## echo 111 > $(pwd)/data/myid

docker run -d --name $node_type \
--restart=always \
-p 8080:8080 \
-e DB_USER=root \
-e DB_PASSWORD=rootroot123 \
-e DB_HOST=192.168.152.100 \
-e DB_PORT=13308 \
-v $(pwd)/logs:/target/log \
$img

echo "sleep 2s"

